package com.gl.config;

import com.gl.handler.CustomHandlerMethodReturnValueHandler;
import com.gl.handler.CustomInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.List;

/**
 * MVC配置类
 * Created by GAOL on 2017/5/13.
 */
@Configuration
public class CostomMvcConfigurer extends WebMvcConfigurerAdapter {

    @Autowired
    private CustomInterceptor globalInterceptor;
    @Autowired
    private CustomHandlerMethodReturnValueHandler customHandlerMethodReturnValueHandler;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册全局自定义拦截器
        registry.addInterceptor(globalInterceptor);
        super.addInterceptors(registry);

    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        super.addCorsMappings(registry);
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        super.addViewControllers(registry);
    }


    @Override
    public void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) {
        returnValueHandlers.add(customHandlerMethodReturnValueHandler);
    }
}
